package com.chis.jxc;

import com.alibaba.fastjson.JSON;
import com.chis.jm.bean.jxc.trace.TraceBean;
import com.chis.jm.bean.jxc.trace.TraceCntStmBean;
import com.chis.jm.bean.qczs.data.TraceErrorData;
import com.chis.jm.pojo.zabbix.TjMntExc;
import com.chis.jmdatatimer.comm.JedisSerializeUtil;
import com.chis.jmdatatimer.comm.TxMgmtModule;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * 
 * @Description  查询mysql同步异常表中的数据TJ_JXC_MNT_EXC
 * @Company zwx
 * @author wlj
 * @version 2019年09月03日
 */
public class JxcExcData {

    public static void main(String[] args) throws Exception {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring.xml"});
        context.start();
        TxMgmtModule txMgmtModule = (TxMgmtModule) context.getBean("TxMgmtModule");
        String opt = args[0];
        if(opt.equals("0")){
            List<TjMntExc> excList  = txMgmtModule.findExcData();
            for(TjMntExc t : excList){
                System.out.println(t.getMark()+"##"+t.getUpdatetime());
                TraceErrorData data = (TraceErrorData) JedisSerializeUtil.unserialize(t.getParam());
                TraceBean traceBean = data.getTraceBean();
                System.out.println(traceBean.getTraceMainBean().getSalCode());
                List<TraceCntStmBean> list = traceBean.getTraceCntStmList();
                for(TraceCntStmBean tdd  : list){
                    String s = tdd.getSrcStorageCode();
                    System.out.println("仓库编码："+s);
                }
                String str = JSON.toJSONString(data);
                System.out.println(str);
            }
        } else if(opt.equals("1")) {
            String code = args[1];
            String guid = args[2];
            String ckcode = args[3];
            List<TjMntExc> excList  = txMgmtModule.findExcData();
            for(TjMntExc t : excList){
                TraceErrorData data = (TraceErrorData) JedisSerializeUtil.unserialize(t.getParam());
                TraceBean traceBean = data.getTraceBean();
                System.out.println(traceBean.getTraceMainBean().getSalCode());
                if(traceBean.getTraceMainBean().getSalCode().equals(code)){
                    List<TraceCntStmBean> list = traceBean.getTraceCntStmList();
                    for(TraceCntStmBean traceCntStmBean : list){
                        if(traceCntStmBean.getSubid().equals(guid)){
                            traceCntStmBean.setSrcStorageCode(ckcode);
                        }
                    }
                    byte[] bytes = JedisSerializeUtil.serialize(data);
                    txMgmtModule.updateJxcExc(t.getRid(),bytes);
                }
            }

        }



    }

}
